//
//  LJJBaseViewController.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/14.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJBaseViewController.h"
#import "LJJHttpTool.h"
#import "UIView+Toast.h"

@interface LJJBaseViewController ()

@end

@implementation LJJBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = MAINCOLOR;
    self.edgesForExtendedLayout = 0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma mark -
#pragma mark - method
- (void)getData:(NSString *)url param:(NSDictionary *)param success:(requestSuccessBlock)returnSuccess error:(requestErrorBlock)returnError
{
    [SVProgressHUD show];
    [LJJHttpTool get:url param:param success:^(id responseObject) {
        [SVProgressHUD dismiss];
        if (returnSuccess) {
            returnSuccess(responseObject);
        }
    } error:^(NSError *error) {
        [SVProgressHUD dismiss];
        [self showTostMessage:@"请求失败，请检查网络"];
        if (returnError) {
            returnError(error);
        }
    }];
}
- (void)postData:(NSString *)url param:(NSDictionary *)param success:(requestSuccessBlock)returnSuccess error:(requestErrorBlock)returnError
{
    [SVProgressHUD show];
    [LJJHttpTool post:url param:param success:^(id responseObject) {
        [SVProgressHUD dismiss];
        if (returnSuccess) {
            returnSuccess(responseObject);
        }
    } error:^(NSError *error) {
        [SVProgressHUD dismiss];
        [self showTostMessage:@"请求失败，请检查网络"];
        if (returnError) {
            returnError(error);
        }
    }];
}
- (void)showTostMessage:(NSString *)tost
{
    [self.view makeToast:tost duration:1.5 position:@"center"];
}

@end
